package com.pineapple.module.web.report;

import java.sql.Connection;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.pineapple.module.core.report.domain.Evolution;
import com.pineapple.module.core.report.domain.EvolutionModel;
import com.pineapple.module.core.report.service.EvolutionManager;
import com.pineapple.module.util.connection.DBCPConnection;

public class EvolutionAction extends ActionSupport implements ModelDriven<EvolutionModel> {

	private static final long serialVersionUID = -3661000161146714152L;
	EvolutionModel model = new EvolutionModel();


	public EvolutionAction(){

		try(Connection conn = new DBCPConnection().getConnection()){
			EvolutionManager manager = new EvolutionManager();
			model.setLstarea(manager.comboArea(conn));

		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	public String init(){
		if(ServletActionContext.getRequest().getSession().getAttribute("user") == null){
			return "init";
		}
		return"search";
	}


	public String search(){
		HttpSession session = ServletActionContext.getRequest().getSession();
        if(session.getAttribute("user")==null){
        	return "init";
        }
		try(Connection conn = new DBCPConnection().getConnection()){
			EvolutionManager manager = new EvolutionManager();
			Evolution evolutions = new Evolution();
			evolutions = manager.search(conn, model.getEvoCri());
			model.setEvo(evolutions);

		}catch(Exception ex){
			ex.printStackTrace();
		}
		return "search";
	}

	@Override
	public EvolutionModel getModel() {
		// TODO Auto-generated method stub
		return model;
	}








}
